"""""""""""""""""""""""""有插件的配置文件vimrc"""""""""""""""""""""""""
"""""""""""""""""""ywvim设置"""""""""""""""""""""""""""""""""""""""""""""
let g:ywvim_ims=[ 
			\['zzdyx', '哲豆音形', 'zzdyx.ywvim'], 
			\['wb98', '五笔98', 'wubi98.ywvim'], 
			\['py', '拼音', 'pinyin.ywvim'], 
			\]

let g:ywvim_py = { 'helpim':'zzdyx', 'gb':0 }
let g:ywvim_zhpunc = 1
let g:ywvim_listmax = 3
let g:ywvim_esc_autoff = 0
let g:ywvim_autoinput = 0
let g:ywvim_intelligent_punc=1
let g:ywvim_circlecandidates = 1
let g:ywvim_helpim_on = 1
let g:ywvim_matchexact = 0
let g:ywvim_chinesecode = 1
let g:ywvim_gb = 0
let g:ywvim_preconv = 'g2b'
let g:ywvim_conv = ''
let g:ywvim_lockb = 0
""""""""""""""""""""""为shell/python文件创建专有设置"""""""""""""""""""""""
autocmd FileType python set tabstop=4 shiftwidth=4 expandtab ai
autocmd FileType java set tabstop=4 shiftwidth=4 expandtab ai
autocmd FileType c,cpp set tabstop=4 shiftwidth=4 expandtab ci
""""""""""""""""根据文件类型自动插入文件头""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""" lua 导入设置""""""""""""""""""""""""
""""""""将lua专属配置放在一个独立的lua.vimrc文件里面
"""""""" 并在templates 目录下有 luaTmp.txt文件。
    if filereadable(expand($VIM_PATH.'/rc/lua.vimrc'))
        source $VIM_PATH/rc/lua.vimrc
    endif
"""""""""""""""""""""" C语言导入设置""""""""""""""""""""""""
""""""""将C专属配置放在一个独立的c.vimrc文件里面
"""""""" 并在templates 目录下有 cTmp.txt文件。
    if filereadable(expand($VIM_PATH.'/rc/c.vimrc'))
        source $VIM_PATH/rc/c.vimrc
    endif
""""""""""""""""""""" python 导入设置""""""""""""""""""""""
""""""""将python专属配置放在一个独立的python.vimrc文件里面
"""""""" 并在templates 目录下有 pythonTmp.txt文件。
    if filereadable(expand($VIM_PATH.'/rc/python.vimrc'))
        source $VIM_PATH/rc/python.vimrc
    endif
"""""""""""""""""""""" bat 导入设置""""""""""""""""""""""""
""""""""将lua专属配置放在一个独立的bat.vimrc文件里面
"""""""" 并在templates 目录下有 batTmp.txt文件。
    if filereadable(expand($VIM_PATH.'/rc/bat.vimrc'))
        source $VIM_PATH/rc/bat.vimrc
    endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufNewFile *.html :0r $VIM_PATH/templates/htmlTmp.txt
" auto add file header
autocmd BufNewFile *.sh :0r $VIM_PATH/templates/shellTmp.txt
autocmd BufNewFile *.sh ks|call FileName()|'s
autocmd BufNewFile *.sh ks|call Version()|'s
autocmd BufNewFile *.sh ks|call CreatedTime()|'s
autocmd FileWritePre,BufWritePre *.sh ks|call ModifyTime()|'s
autocmd BufNewFile *.sh ks|call Author()|'s
autocmd BufNewFile *.sh ks|call Copyright()|'s
autocmd BufNewFile *.sh ks|call Description()|'s
autocmd BufNewFile *.sh normal 10G$vb
autocmd FileWritePre,BufWritePre *.sh 0,10g/Version/norm! $

fun! FileName()
	if line("$") > 10
		let l = 10
	else
		let l = line("$")
	endif
	exe "1," . l . "g/FileName.*/s/FileName.*/File Name       : " .expand("%:t")
endfun

fun! Version()
	if line("$") > 10
		let l = 10
	else
		let l = line("$")
	endif
	exe "1," . l . "g/Version.*/s/Version.*/Version         : 0.0.1" 
endfun

fun! CreatedTime()
    if line("$") > 10
        let l = 10
    else
        let l = line("$")
    endif
    exe "1," . l . "g/CreateTime.*/s/CreateTime.*/Created Time    : " .strftime("%Y-%m-%d %a %H:%M:%S")
endfun
"fun! CreatedTime()
    "let lnum = search('^# \* CreateTime', 'n', 10)
    "if lnum > 0
        "call setline(lnum, "# * Created Time    : " . strftime("%c"))
    "else
        "echo "未找到 CreateTime 行"
    "endif
"endfun

fun! ModifyTime()
    if line("$") > 10
        let l = 10
    else
        let l = line("$")
    endif
    "exe "1," . l . "g/Modified Time.*/s/Modified Time.*/Modified Time   : " .strftime("%c")
    exe "1," . l . "g/Modified Time.*/s/Modified Time.*/Modified Time   : " .strftime("%Y-%m-%d %a %H:%M:%S")
endfun
"fun! ModifyTime()
    "let lnum = search('^# \* Modified Time', 'n', 10)
    "if lnum > 0
        "call setline(lnum, "# * Modified Time   : " . strftime("%c"))
    "else
        "echo "未找到 ModifyTime 行"
    "endif
"endfun

fun! Author()
	if line("$") > 10
		let l = 10
	else
		let l = line("$")
	endif
	exe "1," . l . "g/Author.*/s/Author.*/Author          : Knat" 
endfun

fun! Copyright()
	if line("$") > 10
		let l = 10
	else
		let l = line("$")
	endif
	exe "1," . l . "g/Copyright.*/s/Copyright.*/Copyright       :" "© 2004-" .strftime("%Y"). " Knat. All rights reserved."
endfun

fun! Description()
	if line("$") > 11
		let l = 11
	else
		let l = line("$")
	endif
	exe "1," . l . "g/Description.*/s/Description.*/Description     : " ."……"
endfun
" end auto add file header
"彩虹括号增强版 (Rainbow Parentheses Improved)
"https://github.com/luochen1990/rainbow
let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle
let g:rainbow_conf = {
			\	'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
			\	'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
			\	'operators': '_,_',
			\	'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold', 'start=/</ end=/>/ fold'],
			\	'separately': {
				\		'*': {},
				\		'tex': {
					\			'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
					\		},
					\		'lisp': {
						\			'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
						\		},
						\		'vim': {
							\			'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
							\		},
							\		'html': {
								\			'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
								\		},
								\		'css': 0,
								\	}
								\}
"另一个彩色括号插件，在Gvim 下工作良好"""""""
"let g:rbpt_colorpairs = [
"    \ ['brown',       'RoyalBlue3'],
"    \ ['Darkblue',    'SeaGreen3'],
"    \ ['darkgray',    'DarkOrchid3'],
"    \ ['darkgreen',   'firebrick3'],
"    \ ['darkcyan',    'RoyalBlue3'],
"    \ ['darkred',     'SeaGreen3'],
"    \ ['darkmagenta', 'DarkOrchid3'],
"    \ ['brown',       'firebrick3'],
"    \ ['gray',        'RoyalBlue3'],
"    \ ['darkmagenta', 'DarkOrchid3'],
"    \ ['Darkblue',    'firebrick3'],
"    \ ['darkgreen',   'RoyalBlue3'],
"    \ ['darkcyan',    'SeaGreen3'],
"    \ ['darkred',     'DarkOrchid3'],
"    \ ['red',         'firebrick3'],
"    \ ]
"let g:rbpt_max = 16
"let g:rbpt_loadcmd_toggle = 0
"au VimEnter * RainbowParenthesesToggle
"au Syntax * RainbowParenthesesLoadRound
"au Syntax * RainbowParenthesesLoadSquare
"au Syntax * RainbowParenthesesLoadBraces
"au Syntax * RainbowParenthesesLoadChevrons 
""""""""""""""""""VIM-Plug""""""""""""""""
call plug#begin()
Plug 'mhinz/vim-startify'                         " vim 启动页
Plug 'lilydjwg/fcitx.vim', { 'branch': 'fcitx5' } " fcitx输入法中英文自动切换
Plug 'jiangmiao/auto-pairs'                       " 成对符号自动补全
Plug 'godlygeek/tabular'                          " 表格格式化工具
Plug 'preservim/vim-markdown'                    " markdown 工具
Plug 'hotoo/pangu.vim'                            " 中文文本排版优化
Plug 'machakann/vim-sandwich'                     " 选中文本添加成对符号
Plug 'vim-voom/VOoM'                              " 预览并在侧栏提供目录
Plug 'SirVer/ultisnips'                 "自定义补全文件
Plug 'honza/vim-snippets'               "自定义补全
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
Plug 'luochen1990/rainbow'                                        " 彩虹括号
Plug 'mbbill/fencview'                                            " 格式检测
Plug 'yegappan/mru'                                               " 最近打开文件
Plug 'vim-scripts/ywvim'                                          " 内置输入法
Plug 'mhinz/vim-janah', {'for': 'text'}                           " 颜色主题
Plug 'wsdjeg/ChineseLinter.vim', {'for': 'text'}                  " 中文文档语言规范检查
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " 文件管理器FZF
Plug 'junegunn/fzf.vim'                                           " 文件管理器FZF
Plug 'yianwillis/vimcdoc'                                         "vim中文帮助文档
Plug 'skywind3000/vim-auto-popmenu'				"轻量级补全插件https://github.com/skywind3000/vim-auto-popmenu/
Plug 'skywind3000/vim-dict'					"补全插件的字典服务
Plug 'preservim/nerdcommenter'				"注释插件
Plug 'skywind3000/asynctasks.vim'			"异步运行命令
Plug 'skywind3000/asyncrun.vim'				"配套的任务管理工具
"Plug 'easymotion/vim-easymotion'            "快速移动和搜索工具
Plug 'NLKNguyen/papercolor-theme'           "papercolor主题配色
Plug 'stephpy/vim-yaml'
Plug 'ap/vim-css-color'                     "display color codes
Plug 'monkoose/vim9-stargate'                   "用vim9L重写的easymotion
call plug#end()

"""""""""""""stargate用法"""""""""""""
 " for the start of a word
 noremap <leader>w <Cmd>call stargate#OKvim('\<')<CR>
 " for the end of a word
 noremap <leader>e <Cmd>call stargate#OKvim('\S\>')<CR>
 " for the start of a line
 noremap <leader>l <Cmd>call stargate#OKvim('\_^')<CR>
 " for the last character on the line
 noremap <leader>E <Cmd>call stargate#OKvim('\S\s*$')<CR>
 " for the end of a line
 noremap <leader>$ <Cmd>call stargate#OKvim('$')<CR>
 " for any bracket, parentheses or curly bracket
 noremap <leader>[ <Cmd>call stargate#OKvim('[(){}[\]]')<CR>
"""""""""""""""""""""""vim-auto-popmenu补全插件"""""""""""""""""""""""
" 设定需要生效的文件类型，如果是 "*" 的话，代表所有类型
let g:apc_enable_ft = {'c':1,'txt':0,'markdown':1,'lua':1,'python':1,}
" " 设定从字典文件以及当前打开的文件里收集补全单词，详情看 ':help cpt'
set cpt=.,k,w,b
" " 不要自动选中第一个选项。
set completeopt=menu,menuone,noselect
" " 禁止在下方显示一些啰嗦的提示
set shortmess+=c
"常用命令
"ApcEnable：为当前文档开启补全（比如你没有设置上面的 g:apc_enable_ft 时）
"ApcDisable：为当前文档禁用补全 
"""""""""""""""""""""""""""Asyncrun & Asynctasks""""""""""""""""""""""""
"""Asyncrun相关配置写在语言对应配置文件里面"""
""""语言专属目录 ~/.vim/rc/""""
let g:asyncrun_open = 6	 	"自动打开quickfix 窗口
"配置目录 ~/.vim/tasks.ini
"命令:AsyncTaskList查看所有tasks.ini
"设定快捷键
noremap <silent><f5> :AsyncTask file-run<cr>
noremap <silent><f9> :AsyncTask file-build<cr>
"在标签页打开终端显示输出结果，配合tasks.ini中的output=terminal使用
let g:asynctasks_term_pos = 'external'
"let g:asynctasks_term_pos = 'tab'
"let g:asynctasks_term_pos = 'bottom'
""""""""""""""""ultisnips配置"""""""""""""""""
"自定义目录 mysnippets
let g:UltiSnipsSnippetDirectories=["UltiSnips","mysnippets"]
""自定义版本文件 all.snippets
""""""""""""""Startify""""""""""""""
let g:startify_lists = [
      \ { 'type': 'files',     'header': ['   MRU']            },
      \ { 'type': 'sessions',  'header': ['   Sessions']       },
      \ { 'type': 'bookmarks', 'header': ['   Bookmarks']      },
      \ { 'type': 'commands',  'header': ['   Commands']       },
      \ ]
let g:startify_files_number = 15
let g:startify_bookmarks = [ {'c': '$MYVIMRC'}, {'m': '$VIM_PATH/rc/myplugin.vimrc'}, { 'n': '~/.config/nvim/init.vim' }, {'s': '$VIM_PATH/mysnippets/all.snippets'}, {'r': '~/.local/share/fcitx5/rime/zzdyx_mod.dict.yaml'} ]
""""""""""vim-Markdown""""""""""
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_folding_style_pythonic = 1
let g:vim_markdown_toc_autofit = 1
"""""""""markdown-preview"""""""""
"default browser
"let g:mkdp_browser = '/usr/bin/chromium'
let g:mkdp_browser = has('win32') ? 'C:\Program Files\Mozilla Firefox\firefox.exe' : 
                       \ has('macunix') ? '/Applications/Google Chrome.app' : 
                                          \ '/usr/bin/chromium'
""""""""""""Startify Custom""""""""""""""""
"let g:startify_custom_header = [
"				\'	[.[.    [.   [.    [.   [.       [.   [.    [.[.    [.',
"				\'	[. [. [.[.    [.  [.     [.     [.    [.    [. [. [.[.',
"				\'	[.  [.  [.     [.[.       [.   [.     [.    [.  [.  [.',
"				\'	[.      [.      [.         [. [.      [.    [.      [.',
"				\'	[.      [.      [.          [.        [.    [.      [.',
"				\]
" 
"let g:startify_custom_header = [
"				\'	━━┏━┓┏━┓━━━━┏┓━━┏┓━━━━┏┓━━┏┓━━━━┏━━┓━━━━┏━┓┏━┓━━', 
"				\'	━━┃┃┗┛┃┃━━━━┃┗┓┏┛┃━━━━┃┗┓┏┛┃━━━━┗┫┣┛━━━━┃┃┗┛┃┃━━', 
"				\'	━━┃┏┓┏┓┃━━━━┗┓┗┛┏┛━━━━┗┓┃┃┏┛━━━━━┃┃━━━━━┃┏┓┏┓┃━━', 
"				\'	━━┃┃┃┃┃┃━━━━━┗┓┏┛━━━━━━┃┗┛┃━━━━━━┃┃━━━━━┃┃┃┃┃┃━━', 
"				\'	━━┃┃┃┃┃┃━━━━━━┃┃━━━━━━━┗┓┏┛━━━━━┏┫┣┓━━━━┃┃┃┃┃┃━━', 
"				\'	━━┗┛┗┛┗┛━━━━━━┗┛━━━━━━━━┗┛━━━━━━┗━━┛━━━━┗┛┗┛┗┛━━', 
"                         	\] 
"let g:startify_custom_header = [
"				\'	______  ___  _____  __   ___    __  ________  ______  ___',
"				\'	___   |/  /  ___ | / /   __ |  / /  ____  _/  ___   |/  /',
"				\'	__  /|_/ /   ____|/ /    __ | / /   ___  /    __  /|_/ / ',
"				\'	_  /  / /    ____/ /     __ |/ /    __/ /     _  /  / /  ',
"				\'	/_/  /_/     ___/_/      _____/     /___/     /_/  /_/   ',
"				\]
let g:startify_custom_header = [
			\'	:::=======   🌧️  ::: ===  ✨  :::  ===      :::  🌙  :::======= ',
			\'	::: === ===      ::: ===      :::  ===      :::      ::: === ===',
			\'	=== === ===       =====       ===  ===      ===      === === ===',
			\'	===     ===        ===         ======       ===      ===     ===',
			\'	=== 🕺  ===  🚌    === 🚉 🚏     ==    🚌   === 🚴   ===  🚶 ===',
			\]
"let g:startify_custom_header = [
"				\'	====================================================',
"				\'	==  =====  ==  ====  ==  ======  ==    ==  =====  ==',
"				\'	==   ===   ===  ==  ====  ====  ====  ===   ===   ==',
"				\'	==  =   =  ====    ======  ==  =====  ===  =   =  ==',
"				\'	==  == ==  =====  ========    ======  ===  == ==  ==',
"				\'	==  =====  =====  =========  ======    ==  =====  ==',
"				\'	====================================================',
"				\]
"let g:startify_custom_header = [
"				\'	_________________________________________________',
"				\'	    _   _    _     _    _    _      __     _   _ ',
"				\'	    /  /|     \   /     |   /       /      /  /| ',
"				\'	---/| /-|------\-/------|--/-------/------/| /-|-',
"				\'	  / |/  |       /       | /       /      / |/  | ',
"				\'	_/__/___|____ _/________|/_______/_ ____/__/___|_',
"				\]
let g:startify_custom_footer = [
			\ '		+------------------------------+',
			\ '		|      1.01 ^ 365 =  37.78     |',
			\ '		|      0.99 ^ 365 =   0.02     |',
			\ '		|              `/ /\ () `/ |_| |',
			\ '		+----------------+-------------+',
			\]
